
import { ICommunicator } from './ICommunicator';

export class CommunicatorFactory {
    private static s_Creator: undefined | (() => ICommunicator);
    private static s_Enabled: boolean = true;

    public static get enabled(): boolean {
        return CommunicatorFactory.s_Enabled;
    }

    public static set enabled(value: boolean) {
        CommunicatorFactory.s_Enabled = value;
    }

    public static get communicatorRegistered(): boolean {
        return CommunicatorFactory.s_Creator !== undefined;
    }

    public static create(): ICommunicator | undefined {
        return CommunicatorFactory.s_Enabled ? CommunicatorFactory.s_Creator?.() : undefined;
    }

    public static register<T extends ICommunicator>(creator: () => T): void {
        CommunicatorFactory.s_Creator = creator;
    }

    public static clearCreator(): void {
        CommunicatorFactory.s_Creator = undefined;
    }
}